package com.heng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heng.dao.entity.coupon.CouponTaskFailEntity;
import com.heng.service.CouponTaskFailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/coupon-task-fails")
public class CouponTaskFailController {

    @Autowired
    private CouponTaskFailService failService;

    // 新增失败记录（发放任务执行失败时自动添加）
    @PostMapping
    public boolean addFailRecord(@RequestBody CouponTaskFailEntity failEntity) {
        return failService.save(failEntity);
    }

    // 按ID查询失败记录
    @GetMapping("/{id}")
    public CouponTaskFailEntity getFailRecordById(@PathVariable Long id) {
        return failService.getById(id);
    }

    // 按批次ID查询失败记录
    @GetMapping("/batch/{batchId}")
    public List<CouponTaskFailEntity> getByBatchId(@PathVariable Long batchId) {
        return failService.getByBatchId(batchId);
    }

    // 分页查询失败记录
    @GetMapping("/page")
    public IPage<CouponTaskFailEntity> pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return failService.pageQuery(pageNum, pageSize);
    }
}